package com.zz.wsq.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zz.wsq.model.User;
import com.zz.wsq.service.UserService;

@RestController
public class UserController {
	
	
	@Autowired
	UserService userService;
	@RequestMapping("/wsqlogin")
	public Map login(@RequestParam("name") String userName,@RequestParam("pwd")String pwd){
	Map m=new HashMap();
		String result="N";
		List<User> ls=userService.selectByName(userName);
		if(ls.size()!=0){
			
			if(pwd.equals(ls.get(0).getPwd())){
				result="Y";
			}else{
				result="S";
			}
		}
		m.put("result", result);
		return m;

	}
	
	@RequestMapping("/wsqregister")
	public Map regist(@RequestParam("name") String name,@RequestParam("pwd")String pwd,@RequestParam("email")String email){
	System.out.println(name+pwd);
	Map m=new HashMap();
		String result="N";
		List<User> ls=userService.selectByName(name);
		User u=new User();
		u.setName(name);
		u.setPwd(pwd);
		u.setEmail(email);
		if(ls.size()==0){
			userService.insertSelective(u);
			result="Y";
		}else{
			result="N";
		}
		m.put("result", result);
		return m;

	}

}
